/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lvyh.lightframe.job.client;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Invoke context
 */
public class InvokeContext implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * Scheduling source
     */
    private String source;

    /**
     * The Scheduling password is used for high security and client security verification
     */
    private String password;

    /**
     * Scheduling parameters
     */
    private Map<String, String> params = new HashMap<String, String>();

    public String getString(String name) {
        return getString(name, null);
    }

    public String getString(String name, String defaultValue) {
        if (params == null || params.isEmpty()) {
            return defaultValue;
        }
        String value = params.get(name);
        if (value == null) {
            return defaultValue;
        }
        return value;
    }

    public Integer getInt(String name) {
        return getInt(name, null);
    }

    public Integer getInt(String name, Integer defaultValue) {
        if (params == null || params.isEmpty()) {
            return defaultValue;
        }
        String value = getString(name);
        if (value == null) {
            return defaultValue;
        }
        return Integer.valueOf(value);
    }

    public Long getLong(String name) {
        return getLong(name, null);
    }

    public Long getLong(String name, Long defaultValue) {
        if (params == null || params.isEmpty()) {
            return defaultValue;
        }
        String value = getString(name);
        if (value == null) {
            return defaultValue;
        }
        return Long.valueOf(value);
    }

    public Float getFloat(String name) {
        return getFloat(name, null);
    }

    public Float getFloat(String name, Float defaultValue) {
        if (params == null || params.isEmpty()) {
            return defaultValue;
        }
        String value = getString(name);
        if (value == null) {
            return defaultValue;
        }
        return Float.valueOf(value);
    }

    public Double getDouble(String name) {
        return getDouble(name, null);
    }

    public Double getDouble(String name, Double defaultValue) {
        if (params == null || params.isEmpty()) {
            return defaultValue;
        }
        String value = getString(name);
        if (value == null) {
            return defaultValue;
        }
        return Double.valueOf(value);
    }

    public Boolean getBoolean(String name) {
        return getBoolean(name, null);
    }

    public Boolean getBoolean(String name, Boolean defaultValue) {
        if (params == null || params.isEmpty()) {
            return defaultValue;
        }
        String value = getString(name);
        if (value == null) {
            return defaultValue;
        }
        return Boolean.valueOf(value);
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setParams(Map<String, String> params) {
        this.params = params;
    }

    public Map<String, String> getParams() {
        return params;
    }
}
